package com.bootredis.bootredis.sms;

import com.alibaba.fastjson.JSON;
import com.aliyuncs.*;
import com.aliyuncs.exceptions.*;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

import java.util.HashMap;

public class AddSmsSign {
    public static void main(String[] args) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<LTAI4G2PSpRtmEyS91UHTuGk>", "<SJkwAgEjXtoAvfiFLblNz8ui30V5NA>");
        IAcsClient client = new DefaultAcsClient(profile);
        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("AddSmsSign");
//        request.putQueryParameter("RegionId", "cn-hangzhou");
        //自定义 参数
        request.putQueryParameter("PhoneNumbers","18315722855"); //手机号
        request.putQueryParameter("SignName",""); //签名
        request.putQueryParameter("TemplateCode","SMS_196652885"); //模板CODE  SMS_196652885
        //构建短信验证码
        HashMap<String, Object> objectHashMap = new HashMap<>();
        objectHashMap.put("code",990423);
        request.putQueryParameter("TemplateParam", JSON.toJSONString(objectHashMap)); //短信验证码


        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}
